<?php

Yii::import('zii.widgets.CPortlet');

class UserMenu extends CPortlet
{
    public function init()
    {
        /*$this->title = sprintf('%s <br /> %s: %s',
                               Yum::t('Usermenu'),
                               Yum::t('Logged in as'),
                               Yii::app()->user->data()->username);*/

        $this->contentCssClass = 'menucontent';
        return parent::init();
    }

    public function run()
    {
        $this->widget('YumMenu', array(
                                      'items' => $this->getMenuItems()
                                 ));

        parent::run();
    }

    public function getMenuItems()
    {
        $sections = YumSection::model()->findAll();
        $createItems = array();
        foreach ($sections as $section) {
            $subMenuItem = array();
            $subMenuItem['label'] = $section->name;
            $categories = YumCategory::model()->findAll('section_id=:sectionID', array(':sectionID'=>$section->id));
            $subItem = array();
            foreach($categories as $category) {
                $item = array();
                $item['label'] =  $category->name;
                $item['url'] = array('//blog/post/create/&category_id='.$category->id.'&section_id='.$section->id);
                $subItem[] = $item;
            }
            $subMenuItem['items'] =$subItem;
            $createItems[] = $subMenuItem;
        }
        return array(
            array('label' => 'Create', 'items' => $createItems),
            array('label' => 'Manage Posts', 'url' => array('//blog/post/admin')),
            array('label' => 'Approve Comments', 'url' => array('//blog/comment/index')),
        );
    }
}